package zhihui.mobile.listener;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.widget.EditText;
import com.zgm.utils.ui.MyEditText.onDrawableRightListener;
import zhihui.mobile.R;

/**
 * Created by 张公铭 on 2017/7/13 0013.
 * 密码框右侧图标监听事件
 */
public class EdDrawablePasswordListener implements onDrawableRightListener
{
    private boolean IS_PASSWORD_SHOW = false;
    private Context mContext;

    public EdDrawablePasswordListener(Context context)
    {
        mContext = context;
    }

    @Override
    public void onDrawableRightClick(EditText view)
    {
        //密码可见状态取反
        IS_PASSWORD_SHOW = !IS_PASSWORD_SHOW;
        Drawable drawableright;

        if (IS_PASSWORD_SHOW)
        {
            view.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            drawableright = mContext.getResources().getDrawable(R.drawable.edittext_show);

        } else
        {
            view.setTransformationMethod(PasswordTransformationMethod.getInstance());
            drawableright = mContext.getResources().getDrawable(R.drawable.edittext_dimiss);
        }
        view.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableright, null);
    }
}
